import { Component, HostListener, OnDestroy, OnInit } from "@angular/core";
import { CommService } from "../comm-service";
import { MyhttpService } from "../myhttp.service";
import { sjgzxinModuledatas } from "../pubcomponent/pageTitle.datas";
import { LocalStorageService } from "../local-storage-service";
import { FormBuilder, FormControl, FormGroup } from "@angular/forms";
import { MyValidator } from "../myvalidator-util";

declare var $: any;
declare var AMap: any;

@Component({
  template: `
  <div class="all_bg paddingTop">
    <div class="">
      <div class="marginBottom">
        <ng-container *ngIf="actionobj1.length">
          <portlet-action class="actions" [o]="actionobj1" (outhander)="actionHander($event)"></portlet-action>
        </ng-container>
      </div>
      <div class="portlet-body">
        <div class="row">
          <div class="col-lg-12">
            <div class="tabbable-custom nav-justified">
              <ul class="nav nav-tabs nav-justified">
                <li class="active"><a href="#rwxx" data-toggle="tab" (click)="tabToggle('rwxx')">任务信息</a>
                  <!-- <div class="arrdowm"></div> -->
                </li>
                <li><a href="#glcar" data-toggle="tab" (click)="tabToggle('glcar')">关联运送车辆</a>
                  <!-- <div class="arrdowm"></div> -->
                </li>
                <li><a href="#glry" data-toggle="tab" (click)="tabToggle('glry')">关联押运人员</a>
                  <!-- <div class="arrdowm"></div> -->
                </li>
                <li><a href="#glsb" data-toggle="tab" (click)="tabToggle('glsb')">关联设备信息</a>
                  <!-- <div class="arrdowm"></div> -->
                </li>
              </ul>
              <div class="tab-content">
                <!--任务信息-->
                <div class="tab-pane active" id="rwxx">
                  <div class="row">
                    <form class="form-horizontal" role="form">
                      <div class="col-lg-4 col-lg-offset-3">
                        <div class="form-group">
                          <label class="control-label col-lg-3">运送计划：</label>
                          <div class="col-lg-8">
                            <select name="ysjh" data-live-search="true" id="ysjhselect_rwxx" class="form-control"
                                    [(ngModel)]="s_obj.ysjhbh"></select>
                          </div>
                        </div>
                      </div>
                      <div class="col-lg-4">
                        <div class="form-group">
                          <label class="control-label col-lg-3">运送任务名称：</label>
                          <div class="col-lg-8">
                            <input type="text" class="form-control" name="ysrwmc" [(ngModel)]="s_obj.ysrwmc"/>
                          </div>
                        </div>
                      </div>
                      <div class="col-lg-1">
                        <button type="button" class="btn blue" (click)="inittable_rwxx()">
                          <i class="fa fa-search"></i> 搜索
                        </button>
                      </div>
                    </form>
                  </div>
                  <div class="row">
                    <div class="col-lg-12" *ngIf="table_yyrw_rwxx">
                      <my-table [o]="table_yyrw_rwxx"></my-table>
                    </div>
                  </div>
                </div>
                <!--关联运送车辆-->
                <div class="tab-pane" id="glcar">
                  <div class="row">
                    <form class="form-horizontal" role="form">
                      <div class="col-lg-3">
                        <div class="form-group">
                          <label class="control-label col-lg-3">运送计划：</label>
                          <div class="col-lg-8">
                            <select name="ysjh" data-live-search="true" id="ysjhselect_glcar" class="form-control"
                                    [(ngModel)]="s_obj_glxx.ysjhbh"></select>
                          </div>
                        </div>
                      </div>
                      <div class="col-lg-4">
                        <div class="form-group">
                          <label class="control-label col-lg-3">运送任务名称：</label>
                          <div class="col-lg-8">
                            <input type="text" class="form-control" name="ysrwmc" [(ngModel)]="s_obj_glxx.ysrwmc"/>
                          </div>
                        </div>
                      </div>
                      <div class="col-lg-4">
                        <div class="form-group">
                          <label class="control-label col-lg-3">关联车辆：</label>
                          <div class="col-lg-8">
                            <select class="form-control" id="glcar_select" name="sfgl"
                                    [(ngModel)]="s_obj_glxx.sfglcl" (change)="inittable_glxx()"></select>
                          </div>
                        </div>
                      </div>
                      <div class="col-lg-1">
                        <button type="button" class="btn blue" (click)="inittable_glxx()">
                          <i class="fa fa-search"></i> 搜索
                        </button>
                      </div>
                    </form>
                  </div>
                  <div class="row">
                    <div class="col-lg-12" *ngIf="table_yyrw_glxx_car">
                      <my-table [o]="table_yyrw_glxx_car"></my-table>
                    </div>
                  </div>
                </div>
                <!--关联押运人员-->
                <div class="tab-pane" id="glry">
                  <div class="row">
                    <form class="form-horizontal" role="form">
                      <div class="col-lg-3">
                        <div class="form-group">
                          <label class="control-label col-lg-3">运送计划：</label>
                          <div class="col-lg-8">
                            <select name="ysjh" data-live-search="true" id="ysjhselect_glry" class="form-control"
                                    [(ngModel)]="s_obj_glxx.ysjhbh"></select>
                          </div>
                        </div>
                      </div>
                      <div class="col-lg-4">
                        <div class="form-group">
                          <label class="control-label col-lg-3">运送任务名称：</label>
                          <div class="col-lg-8">
                            <input type="text" class="form-control" name="ysrwmc" [(ngModel)]="s_obj_glxx.ysrwmc"/>
                          </div>
                        </div>
                      </div>
                      <div class="col-lg-4">
                        <div class="form-group">
                          <label class="control-label col-lg-3">关联人员：</label>
                          <div class="col-lg-8">
                            <select class="form-control" id="glry_select" name="sfgl"
                                    [(ngModel)]="s_obj_glxx.sfglry" (change)="inittable_glxx()"></select>
                          </div>
                        </div>
                      </div>
                      <div class="col-lg-1">
                        <button type="button" class="btn blue" (click)="inittable_glxx()">
                          <i class="fa fa-search"></i> 搜索
                        </button>
                      </div>
                    </form>
                  </div>
                  <div class="row">
                    <div class="col-lg-12" *ngIf="table_yyrw_glxx_ry">
                      <my-table [o]="table_yyrw_glxx_ry"></my-table>
                    </div>
                  </div>
                </div>
                <!--关联设备信息-->
                <div class="tab-pane" id="glsb">
                  <div class="row">
                    <form class="form-horizontal" role="form">
                      <div class="col-lg-3">
                        <div class="form-group">
                          <label class="control-label col-lg-3">运送计划：</label>
                          <div class="col-lg-8">
                            <select name="ysjh" data-live-search="true" id="ysjhselect_glsb" class="form-control"
                                    [(ngModel)]="s_obj_glxx.ysjhbh"></select>
                          </div>
                        </div>
                      </div>
                      <div class="col-lg-4">
                        <div class="form-group">
                          <label class="control-label col-lg-3">运送任务名称：</label>
                          <div class="col-lg-8">
                            <input type="text" class="form-control" name="ysrwmc" [(ngModel)]="s_obj_glxx.ysrwmc"/>
                          </div>
                        </div>
                      </div>
                      <div class="col-lg-4">
                        <div class="form-group">
                          <label class="control-label col-lg-3">关联设备：</label>
                          <div class="col-lg-8">
                            <select class="form-control" id="glsb_select" name="sfgl"
                                    [(ngModel)]="s_obj_glxx.sfglsb" (change)="inittable_glxx()"></select>
                          </div>
                        </div>
                      </div>
                      <div class="col-lg-1">
                        <button type="button" class="btn blue" (click)="inittable_glxx()">
                          <i class="fa fa-search"></i> 搜索
                        </button>
                      </div>
                    </form>
                  </div>
                  <div class="row">
                    <div class="col-lg-12" *ngIf="table_yyrw_glxx_sb">
                      <my-table [o]="table_yyrw_glxx_sb"></my-table>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="modal fad" id="dtwl_Modal" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel">
      <div class="modal-dialog bigmodalwidth" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
              aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModalLabel">地图围栏</h4>
          </div>
          <div class="modal-body">
            <div class="row">
              <div class="col-lg-12" style="position: relative">
                <div id="mapRoom"></div>
                <div class="clearbtn" *ngIf="dtwlactionflag=='edite'" (click)="clearDtwl()">清空原围栏</div>
              </div>
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
            <button *ngIf="dtwlactionflag!='view'" type="button" class="btn btn-primary" (click)="dtwlDone()">确 定
            </button>
          </div>
        </div>
      </div>
    </div>
    <div class="modal fad" id="add_rwbasexxModal" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel">
      <div class="modal-dialog smmodalwidth" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
              aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModalLabel">修改任务信息</h4>
          </div>
          <div class="modal-body">
            <div class="row">
              <form class="form-horizontal" role="form" [formGroup]="formgroup_rwbasexx">
                <div class="col-lg-12">
                  <div class="form-group">
                    <label class="col-lg-3 control-label">
                      总负责人姓名:
                    </label>
                    <div class="col-lg-8">
                      <input type="text" class="form-control" formControlName="zfzrxmCtr"/>
                    </div>
                  </div>
                </div>
                <div class="col-lg-12">
                  <div class="form-group">
                    <label class="col-lg-3 control-label">
                      证件类型:
                    </label>
                    <div class="col-lg-8">
                      <select class="form-control" name="sfzjlxm" id="sfzjlxselect"
                              formControlName="sfzjlxmCtr"></select>
                    </div>
                  </div>
                </div>
                <div class="col-lg-12">
                  <div class="form-group">
                    <label class="col-lg-3 control-label">
                      证件号码:
                    </label>
                    <div class="col-lg-8">
                      <input type="text" class="form-control" formControlName="sfzjhmCtr"/>
                      <div
                        *ngIf="formgroup_rwbasexx.get('sfzjhmCtr').invalid&&formgroup_rwbasexx.get('sfzjhmCtr').dirty">
                        <span *ngIf="formgroup_rwbasexx.hasError('numMatchlx','sfzjhmCtr')">
                          <tool-tip [o]="formgroup_rwbasexx.getError('numMatchlx','sfzjhmCtr').msg"></tool-tip>
                        </span>
                      </div>
                    </div>
                  </div>
                </div>
              </form>
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
            <button type="button" class="btn btn-primary" (click)="sure_editeRwxx()">确 定</button>
          </div>
        </div>
      </div>
    </div>
    <div class="modal fad" id="glcar_Modal" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel">
      <div class="modal-dialog bigmodalwidth" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
              aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModalLabel">选择关联车辆</h4>
          </div>
          <div class="modal-body">
            <div class="row">
              <div class="form-horizontal" role="form">
                <div class="col-lg-offset-8 col-lg-3">
                  <div class="form-group">
                    <label class="col-lg-3 control-label">车牌号</label>
                    <div class="col-lg-8">
                      <input type="text" class="form-control" name="cph" [(ngModel)]="s_obj_gltablecar.cph"/>
                    </div>
                  </div>
                </div>
                <div class="col-lg-1">
                  <button type="button" class="btn blue" (click)="inittable_glcar()"><i class="fa fa-search"></i> 搜索
                  </button>
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-lg-12" *ngIf="gltable_car">
                <my-table [o]="gltable_car" (outhander)="tableHander($event)"></my-table>
              </div>
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
            <button type="button" class="btn btn-primary" (click)="glsureDone('car')">确 定</button>
          </div>
        </div>
      </div>
    </div>
    <div class="modal fad" id="glry_Modal" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel">
      <div class="modal-dialog bigmodalwidth" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
              aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModalLabel">选择关联人员</h4>
          </div>
          <div class="modal-body">
            <div class="row">
              <form class="form-horizontal" role="form">
                <div class="col-lg-3">
                  <div class="form-group">
                    <label class="control-label col-lg-4">姓名：</label>
                    <div class="col-lg-8">
                      <input type="text" class="form-control" placeholder="姓名" name="xm"
                             [(ngModel)]="s_obj_gltablery.xm"/>
                    </div>
                  </div>
                </div>
                <div class="col-lg-4">
                  <div class="form-group">
                    <label class="control-label col-lg-4">身份证号：</label>
                    <div class="col-lg-8">
                      <input type="text" class="form-control" placeholder="身份证号" name="sfzjhm"
                             [(ngModel)]="s_obj_gltablery.sfzjhm"/>
                    </div>
                  </div>
                </div>
                <div class="col-lg-4">
                  <div class="form-group">
                    <label class="control-label col-lg-4">人员类型：</label>
                    <div class="col-lg-8">
                      <select class="form-control" id="rylxSelect" name="rylx"
                              [(ngModel)]="s_obj_gltablery.rylxm"></select>
                    </div>
                  </div>
                </div>
                <div class="ccol-lg-1">
                  <button type="button" class="btn blue" (click)="inittable_glry()">
                    <i class="fa fa-search"></i> 搜索
                  </button>
                </div>
              </form>
            </div>
            <div class="row">
              <div class="col-lg-8" *ngIf="gltable_ry">
                <my-table [o]="gltable_ry" (outhander)="tableHander($event)"></my-table>
              </div>
              <div class="col-lg-4">
                <div class="cache_title xqheader">
                  <h4 style="float:left">已选人员</h4>
                  <div style="float:right;">
                    <a href="javascript:void(0)" style="color:#fff;" title="清空" (click)="removeAll_selectdry()"><i
                      class="fa fa-bank"></i> 清空</a>
                  </div>
                </div>
                <ul *ngIf="selectryCache.length" class="cache_room">
                  <li *ngFor="let item of selectryCache;index as index" class="cache_item"
                      (mouseenter)="showRemovebtn(item)"
                      (mouseleave)="hideRemovebtn(item)">
                    <div class="removeCachebtn" *ngIf="item.showremovecellbtn" (click)="removeryCache(item,index)"><i
                      class="fa fa-minus-circle"></i></div>
                    {{item.xm}}
                  </li>
                </ul>
              </div>
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
            <button type="button" class="btn btn-primary" (click)="glsureDone('ry')">确 定</button>
          </div>
        </div>
      </div>
    </div>

    <div class="modal fad" id="glsb_Modal" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel">
      <div class="modal-dialog bigmodalwidth" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
              aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModalLabel">选择关联设备</h4>
          </div>
          <div class="modal-body">
            <div class="row">
              <div class="col-lg-12">
                <div class="tabbable-custom nav-justified">
                  <ul class="nav nav-tabs nav-justified">
                    <li class="active"><a href="#gl_zdsb" data-toggle="tab" (click)="tabTogglegl('glzdsb')">手持终端设备</a>
                      <!-- <div class="arrdowm"></div> -->
                    </li>
                    <li><a href="#gl_dzbqsb" data-toggle="tab" (click)="tabTogglegl('gldzbqsb')">电子标签</a>
                      <!-- <div class="arrdowm"></div> -->
                    </li>
                  </ul>
                  <div class="tab-content">
                    <!--手持终端设备-->
                    <div class="tab-pane active" id="gl_zdsb">
                      <div class="row">
                        <form class="form-horizontal" role="form">
                          <div class="col-lg-5 col-lg-offset-6">
                            <div class="form-group">
                              <label class="col-lg-3 control-label">手持终端id:</label>
                              <div class="col-lg-8">
                                <input type="text" class="form-control" name="id" [(ngModel)]="s_obj_gltablezdsb.id"/>
                              </div>
                            </div>
                          </div>
                          <div class="col-lg-1">
                            <button type="button" class="btn blue" (click)="inittable_glsb_zdsb()">
                              <i class="fa fa-search"></i> 搜索
                            </button>
                          </div>
                        </form>
                      </div>
                      <div class="row">
                        <div class="col-lg-12" *ngIf="gltable_zdsb">
                          <my-table [o]="gltable_zdsb" (outhander)="tableHander($event)"></my-table>
                        </div>
                      </div>
                    </div>
                    <!--电子标签-->
                    <div class="tab-pane" id="gl_dzbqsb">
                      <div class="row">
                        <div class="col-lg-8" *ngIf="gltable_bqsb">
                          <!--<div class="row">-->
                          <!--<form class="form-horizontal" role="form">-->
                          <!--<div class="col-lg-5 col-lg-offset-5">-->
                          <!--<div class="form-group">-->
                          <!--<label class="col-lg-4 control-label">标签id：</label>-->
                          <!--<div class="col-lg-8">-->
                          <!--<input type="text" class="form-control" name="id"-->
                          <!--[(ngModel)]="s_obj_gltablebqsb.id"/>-->
                          <!--</div>-->
                          <!--</div>-->
                          <!--</div>-->
                          <!--<div class="col-lg-1">-->
                          <!--<button class="btn blue" (click)="inittable_glsb_dzbqsb()">-->
                          <!--<i class="fa fa-search"></i> 搜索-->
                          <!--</button>-->
                          <!--</div>-->
                          <!--</form>-->
                          <!--</div>-->
                          <div class="row">
                            <div class="col-lg-12">
                              <my-table [o]="gltable_bqsb" (outhander)="tableHander($event)"></my-table>
                            </div>
                          </div>
                        </div>
                        <div class="col-lg-4">
                          <div class="cache_title xqheader">
                            <h4 style="float:left">已选标签设备</h4>
                            <div style="float:right;">
                              <a href="javascript:void(0)" style="color:#fff;" title="清空"
                                 (click)="removeAll_selectdbqsb()"><i
                                class="fa fa-bank"></i> 清空</a>
                            </div>
                          </div>
                          <ul *ngIf="selectbqsbCache.length" class="cache_room">
                            <li *ngFor="let item of selectbqsbCache;index as index" class="cache_item"
                                (mouseenter)="showRemovebtn(item)"
                                (mouseleave)="hideRemovebtn(item)">
                              <div class="removeCachebtn" *ngIf="item.showremovecellbtn"
                                   (click)="removebqsbCache(item,index)"><i
                                class="fa fa-minus-circle"></i></div>
                              {{item.id}}
                            </li>
                          </ul>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
            <button type="button" class="btn btn-primary" (click)="glsureDone('sb')">确 定</button>
          </div>
        </div>
      </div>
    </div>
    <div class="modal fad" id="xq_kglbqsjbModal" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel">
      <div class="modal-dialog smmodalwidth" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
              aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModalLabel">试卷包信息</h4>
          </div>
          <div class="modal-body">
            <div class="row">
              <div class="col-lg-12" *ngIf="xqobj_sjbxx">
                <xq-form [o]="xqobj_sjbxx"></xq-form>
              </div>
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">关 闭</button>
          </div>
        </div>
      </div>
    </div>

    <div class="modal fad" id="viewglxx_Modal" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel">
      <div class="modal-dialog smmodalwidth" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
              aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModalLabel">关联试卷包信息</h4>
          </div>
          <div class="modal-body">
            <div class="row">
              <div class="col-lg-12">
                <table class="table table-bordered">
                  <thead>
                  <tr>
                    <th>试卷包名称</th>
                    <th>电子标签id</th>
                  </tr>
                  </thead>
                  <tbody *ngIf="glsjbxxList.length">
                  <tr *ngFor="let row of glsjbxxList">
                    <td>{{row.sjbmc}}</td>
                    <td>{{row.dzbqid}}</td>
                  </tr>
                  </tbody>
                </table>
              </div>
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
          </div>
        </div>
      </div>
    </div>
    </div>
  `,
  styles: [
    "#mapRoom{width: 100%;height: 500px}",
    ".clearbtn{position: absolute;top: 10px;right: 20px;width: 150px;height: 30px;line-height: 30px;text-align: center;background-color: grey;color: #fff;cursor: pointer}",
    ".cache_title{height: 40px;line-height: 40px;background-color:#32c5d2;text-align: center;color: #fff}",
    " .xqheader{height:40px;padding:0px 15px;border-bottom: 1px solid #e5e5e5;}",
    " .xqheader h4{font-size:14px;font-weight:600;}",
    ".cache_room{list-style: none;margin-bottom: 0px;max-height: 460px;overflow-y: auto}",
    ".cache_item{padding: 10px 5px;background-color: #ebf5ec;margin: 5px;position: relative}",
  ]
})

export class YyrwComponent implements OnInit, OnDestroy {
  userinfo: any;
  activeTab: string = "rwxx";
  s_obj: any = {
    ysrwmc: "",
    ysjhbh: "",  //运送计划编号
    ksjhbh: "",
    sfglry: "", // 是否关联人员 0 关联；1 未关联 "" 全部
    sfglcl: "", //是否关联车辆：0 关联；1 未关联  ""全部
    sfglsb: "", // 是否关联设备：0 关联；1 未关联  ""全部
  };
  table_yyrw_rwxx: any;
  // 三个关联表格，用同一个查询参数，表格用不同的对象（否则会一个tab,查询三次）
  s_obj_glxx: any = {
    ysrwmc: "",
    ysjhbh: "",  //运送计划编号
    ksjhbh: "",
    sfglry: "1", // 是否关联人员 0 关联；1 未关联 "" 全部
    sfglcl: "1", //是否关联车辆：0 关联；1 未关联  ""全部
    sfglsb: "1", // 是否关联设备：0 关联；1 未关联  ""全部
  };
  selectDefaultField: any = {
    sfglry: "",
    sfglcl: "",
    sfglsb: "",
    // 修改任务基础信息表单需要
    sfzjlxm: ''
  };
  table_yyrw_glxx_car: any;
  table_yyrw_glxx_ry: any;
  table_yyrw_glxx_sb: any;
  actionobj1: any[] = [];
  yyrw_btns: any[] = ["yyrw_xtsc", "yyrw_bindgx"];
  yyrw_c_btns: any[] = ["view_dzwl", "eidte_dzwl", "eidte_rwxx", "glkz_yyrw", "ckglxx_yyrw"];
  hascbtns: any[] = [];
  yyrwztKeyValue: any = {
    "1": "已完成",
    "2": "未完成",
    "3": "未开始"
  };
  caozuo_ysrwwybsm: string;  // 状态信息使用
  caozuo_ysrwbh: string;  // 关联  解除关联使用
  map: any;
  polygonList: any[] = []; // 多边形对象集合
  viewpolygon: any;
  dtwlactionflag: string = ""; // view--查看   add---添加   edite--编辑
  cfdMarker: any;
  mddMarker: any;
  formgroup_rwbasexx: FormGroup;
  //########### 车
  s_obj_gltablecar: any = {
    cph: "",
    sfglrw: "1" // 未关联
  };
  gltable_car: any;
  glbh_car: any[] = []; // 当前选择要关联的车辆编号数组
  //############人
  s_obj_gltablery: any = {
    xm: "",
    sfzjhm: "",
    rylxm: "",
    sfglrw: "1" // 未关联
  }
  gltable_ry: any;
  selectryCache: any[] = [];

  //###########设备-手持终端
  activeTab_gl: string = "glzdsb";
  s_obj_gltablezdsb: any = {
    sfgldzbq: "0",  //1 --未关联电子标签  0 --已关联电子标签  ""--全部
    ksjhbh: "",
    id: "" //手持终端id
  };
  gltable_zdsb: any;
  glbh_zdsb: any[] = [];// 当前选择要关联的手持终端设备编号数组
  //######### 设备----电子标签
  s_obj_gltablebqsb: any = {
    ksjhbh: "",
  };
  gltable_bqsb: any;
  selectbqsbCache: any[] = [];
  xqobj_sjbxx: any;
  glsjbxxList: any[] = [];

  /**
   * 初始化按钮
   */
  initactions(): void {
    // this.commservice.getroleBtns(this.yyrw_btns, this.yyrw_c_btns, this.userinfo.nowroleid, "table_yyrw_rwxx", (hasportbtns, hastablebtns) => {
    //   this.actionobj1 = hasportbtns;
    //   this.hascbtns = hastablebtns;
    // });
    this.commservice.getroleBtns_not_permissions(this.yyrw_btns, this.yyrw_c_btns, "table_yyrw_rwxx", (hasportbtns, hastablebtns) => {
      this.actionobj1 = hasportbtns;
      this.hascbtns = hastablebtns;
    });
  }

  /**
   * 按钮的处理回调
   * @param e
   */
  actionHander(e: any): void {
    const fromv = e.pfrom;
    const actiontype = e.type;
    if (fromv === "table_yyrw_rwxx") {
      if (actiontype === "xtsc") {
        //系统一键生成  运送任务+ 运送计划
        this.createyswh_ysjh();
      } else if (actiontype == "bindgx") {
        //系统一键绑定关联关系  标签和试卷包，终端和标签
        this.bindGlGx();
      }
    }
  }

  /**
   * 系统一键生成  运送任务+ 运送计划
   */
  createyswh_ysjh(): void {
    this.commservice.blockUI({
      boxed: true,
      message: "处理中...",
      zIndex: 10051,
      overlayColor: "#67809F"
    });
    const url = "sjgz/rwjh/xtscysrw";
    this.itservice.kwPtPost(url, {
      ksjhbh: this.s_obj.ksjhbh
    }).subscribe(resp => {
      this.commservice.handResponse("put", url, resp, (arg1, resp, arg2) => {
        if (arg1) {
          if (arg2) {
            this.table_yyrw_rwxx = Object.assign({}, this.table_yyrw_rwxx);
            this.commservice.myswal("success", "生成运送任务完成!", "", "ts", null);
          }
        }
      });
    });
  }

  /**
   * 系统一键绑定关联关系  标签和试卷包，终端和标签
   */
  bindGlGx(): void {
    this.commservice.blockUI({
      boxed: true,
      message: "处理中...",
      zIndex: 10051,
      overlayColor: "#67809F"
    });
    const url = "sjgz/rwjh/xtbdglgx";
    this.itservice.kwPtPost(url, {
      ksjhbh: this.s_obj.ksjhbh
    }).subscribe(resp => {
      this.commservice.handResponse("put", url, resp, (arg1, resp, arg2) => {
        if (arg1) {
          if (arg2) {
            this.commservice.myswal("success", "绑定关联关系完成!", "", "ts", null);
          }
        }
      });
    });
  }

  /**
   *
   * @param {string} tabv
   * rwxx
   * glcar
   * glry
   * glsb
   */
  tabToggle(tabv: string): void {
    this.activeTab = tabv;
    if (this.activeTab == "rwxx") {
      $("#ysjhselect_rwxx").selectpicker("val", "");
      this.s_obj.ysjhbh = "";
      this.inittable_rwxx();
    } else {
      if (tabv == "glcar") {
        $("#glcar_select").selectpicker("val", this.selectDefaultField.sfglcl);
        this.s_obj_glxx.sfglcl = this.selectDefaultField.sfglcl; // 是否关联车辆
        this.s_obj_glxx.sfglry = "";
        this.s_obj_glxx.sfglsb = "";
        $("#ysjhselect_glcar").selectpicker("val", "");
        this.s_obj_glxx.ysjhbh = "";
      } else if (tabv == "glry") {
        $("#glry_select").selectpicker("val", this.selectDefaultField.sfglry);
        this.s_obj_glxx.sfglry = this.selectDefaultField.sfglry; // 是否关联人员
        this.s_obj_glxx.sfglcl = "";
        this.s_obj_glxx.sfglsb = "";
        $("#ysjhselect_glry").selectpicker("val", "");
        this.s_obj_glxx.ysjhbh = "";
      } else if (tabv == "glsb") {
        $("#glsb_select").selectpicker("val", this.selectDefaultField.sfglsb);
        this.s_obj_glxx.sfglsb = this.selectDefaultField.sfglsb; // 是否关联设备
        this.s_obj_glxx.sfglcl = "";
        this.s_obj_glxx.sfglry = "";
        $("#ysjhselect_glsb").selectpicker("val", "");
        this.s_obj_glxx.ysjhbh = "";
      }
      this.inittable_glxx();
    }
  }

  /**
   * 任务基本信息表格
   */
  inittable_rwxx(): void {
    const that = this;
    this.table_yyrw_rwxx = {
      tableid: "table_yyrw_rwxx",
      url: "sjgz/rwjh/cxysrwlb",
      reqobj: this.s_obj,
      sidePagination: "server",
      pageSize: 10,
      pageList: [10, 20, 30],
      total: "totalRows",
      rows: "cxysrwList",
      columns: [{
        title: "序号",
        field: "ordernum",
        cellStyle: function () {
          return {
            classes: 'td1'
          }
        }
      }, {
        title: "运送任务名称",
        field: "ysrwmc",
        cellStyle: function () {
          return {
            classes: 'td2'
          }
        }
      }, {
        title: "出发地",
        field: "cfdmc",
        cellStyle: function () {
          return {
            classes: 'td3'
          }
        }
      }, {
        title: "目的地",
        field: "mddmc",
        cellStyle: function () {
          return {
            classes: 'td4'
          }
        }
      }, {
        title: "开始时间",
        field: "rwkssj",
        cellStyle: function () {
          return {
            classes: 'td1'
          }
        }
      }, {
        title: "结束时间",
        field: "rwjssj",
        cellStyle: function () {
          return {
            classes: 'td2'
          }
        }
      }, {
        title: "地图围栏",
        field: "dtwl",
        cellStyle: function () {
          return {
            classes: 'td3'
          }
        },
        events: this.myevents,
        formatter: function (v) {
          let str = "";
          if (that.hascbtns.indexOf("view_dzwl") != -1) {
            if (v) {
              str += "<button type='button' class='btn btn-xs btn-info view_dzwl'><i class='fa fa-eye'></i> 查看</button>";
            }
          }
          if (that.hascbtns.indexOf("eidte_dzwl") != -1) {
            if (v) {
              str += "<button type='button' class='btn btn-xs btn-primary eidte_dzwl'><i class='fa fa-pencil'></i> 修改</button>";
            } else {
              str += "<button type='button' class='btn btn-xs btn-primary eidte_dzwl'><i class='fa fa-pencil'></i> 设置</button>";
            }
          }
          return str;
        }
      }, {
        title: "任务完成状态",
        field: "rwwczt",
        cellStyle: function () {
          return {
            classes: 'td4'
          }
        },
        formatter: function (v) {
          return that.yyrwztKeyValue[v] ? that.yyrwztKeyValue[v] : ''
        }
      }, {
        title: "操作",
        field: "ysrwwybsm",
        events: this.myevents,
        formatter: function (v) {
          let str = "";
          if (that.hascbtns.indexOf("eidte_rwxx") != -1) {
            str += "<button type='button' class='btn btn-xs btn-primary eidte_rwxx'><i class='fa fa-pencil'></i> 修改</button>";
          }
          return str;
        }
      }]
    }
    // this.table_yyrw_rwxx.pageSize = 50;
    // this.table_yyrw_rwxx.pageList = [50];
    // this.table_yyrw_rwxx.hiddenPageinfoLink = true;
    // this.table_yyrw_rwxx.paginationLoop = true;
    // this.table_yyrw_rwxx.paginationPreText = "<i class='fa fa-arrow-left'></i>上一页";
    // this.table_yyrw_rwxx.paginationNextText = "下一页<i class='fa fa-arrow-right'></i>";
    // this.table_yyrw_rwxx.height = this.commservice.getViewPort().height - this.commservice.topH - this.commservice.topmenuH - 240 - 110;
    this.table_yyrw_rwxx.height = this.commservice.getViewPort().height - this.commservice.topH - this.commservice.topmenuH - 240 - 110;
  }

  /**
   * 任务关联  车联/押运人员/设备的表格
   */
  inittable_glxx(): void {
    const that = this;
    const obj = {
      tableid: "",
      url: "sjgz/rwjh/cxysrwlb",
      reqobj: this.s_obj_glxx,
      sidePagination: "server",
      pageSize: 10,
      pageList: [10, 20, 30],
      total: "totalRows",
      rows: "cxysrwList",
      columns: [{
        title: "序号",
        field: "ordernum",
        cellStyle: function () {
          return {
            classes: 'td1'
          }
        }
      }, {
        title: "运送任务名称",
        field: "ysrwmc",
        cellStyle: function () {
          return {
            classes: 'td2'
          }
        }
      }, {
        title: "出发地",
        field: "cfdmc",
        cellStyle: function () {
          return {
            classes: 'td3'
          }
        }
      }, {
        title: "目的地",
        field: "mddmc",
        cellStyle: function () {
          return {
            classes: 'td4'
          }
        }
      }, {
        title: "开始时间",
        field: "rwkssj",
        cellStyle: function () {
          return {
            classes: 'td1'
          }
        }
      }, {
        title: "结束时间",
        field: "rwjssj",
        cellStyle: function () {
          return {
            classes: 'td2'
          }
        }
      }, {
        title: "任务完成状态",
        field: "rwwczt",
        cellStyle: function () {
          return {
            classes: 'td3'
          }
        },
        formatter: function (v) {
          return that.yyrwztKeyValue[v] ? that.yyrwztKeyValue[v] : ''
        }
      }, {
        title: "操作",
        field: "ysrwbh",
        events: this.myevents,
        formatter: function (v) {
          let str = "";
          if (that.hascbtns.indexOf("glkz_yyrw") != -1) {
            if (that.activeTab == "glcar") {
              // 当前tab 是 【关联送车辆】
              if (that.s_obj_glxx.sfglcl == "0") {
                // 查询出来的是 已经关联的
                str += "<button type='button' class='btn btn-xs btn-primary jcgl_car'><i class='fa fa-unlock'></i>  解除关联</button>";
              } else {
                // 查询出来的是  未关联的
                str += "<button type='button' class='btn btn-xs btn-primary gl_car'><i class='fa fa-lock'></i>  关联车辆</button>";
              }
            } else if (that.activeTab == "glry") {
              // 当前tab 是   【关联押运人员】
              if (that.s_obj_glxx.sfglry == "0") {
                // 查询出来的是 已经关联的
                str += "<button type='button' class='btn btn-xs btn-primary jcgl_ry'><i class='fa fa-unlock'></i>  解除关联</button>";
              } else {
                // 查询出来的是  未关联的
                str += "<button type='button' class='btn btn-xs btn-primary gl_ry'><i class='fa fa-lock'></i>  关联人员</button>";
              }
            } else if (that.activeTab == "glsb") {
              // 当前 tab 是   【关联设备信息】
              if (that.s_obj_glxx.sfglsb == "0") {
                // 查询出来的是 已经关联的
                str += "<button type='button' class='btn btn-xs btn-primary jcgl_sb'><i class='fa fa-unlock'></i>  解除关联</button>";
              } else {
                // 查询出来的是  未关联的
                str += "<button type='button' class='btn btn-xs btn-primary gl_sb'><i class='fa fa-lock'></i>  关联设备</button>";
              }
            }
          }
          if (that.hascbtns.indexOf("ckglxx_yyrw") != -1) {
            if (that.activeTab == "glsb") {
              // 当前 tab 是   【关联设备信息】
              if (that.s_obj_glxx.sfglsb == "0") {
                // 查询出来的是 已经关联的
                str += "<button type='button' class='btn btn-xs btn-primary ckglxx_yyrw'><i class='fa fa-eye'></i>  查看关联信息</button>";
              }
            }
          }
          return str;
        }
      }]
    }
    if (this.activeTab == "glcar") {
      obj["tableid"] = "table_yyrw_glxx_car";
      this.table_yyrw_glxx_car = Object.assign({}, obj);
      // this.table_yyrw_glxx_car.pageSize = 50;
      // this.table_yyrw_glxx_car.pageList = [50];
      // this.table_yyrw_glxx_car.hiddenPageinfoLink = true;
      // this.table_yyrw_glxx_car.paginationLoop = true;
      // this.table_yyrw_glxx_car.paginationPreText = "<i class='fa fa-arrow-left'></i>上一页";
      // this.table_yyrw_glxx_car.paginationNextText = "下一页<i class='fa fa-arrow-right'></i>";
      // this.table_yyrw_glxx_car.height = this.commservice.getViewPort().height - this.commservice.topH - this.commservice.topmenuH - 240 - 110;
      this.table_yyrw_glxx_car.height = this.commservice.getViewPort().height - this.commservice.topH - this.commservice.topmenuH - 240 - 110;
    } else if (this.activeTab == 'glry') {
      obj["tableid"] = "table_yyrw_glxx_ry";
      this.table_yyrw_glxx_ry = Object.assign({}, obj);
      // this.table_yyrw_glxx_ry.pageSize = 50;
      // this.table_yyrw_glxx_ry.pageList = [50];
      // this.table_yyrw_glxx_ry.hiddenPageinfoLink = true;
      // this.table_yyrw_glxx_ry.paginationLoop = true;
      // this.table_yyrw_glxx_ry.paginationPreText = "<i class='fa fa-arrow-left'></i>上一页";
      // this.table_yyrw_glxx_ry.paginationNextText = "下一页<i class='fa fa-arrow-right'></i>";
      // this.table_yyrw_glxx_ry.height = this.commservice.getViewPort().height - this.commservice.topH - this.commservice.topmenuH - 240 - 110;
      this.table_yyrw_glxx_ry.height = this.commservice.getViewPort().height - this.commservice.topH - this.commservice.topmenuH - 240 - 110;
    } else if (this.activeTab == "glsb") {
      obj["tableid"] = "table_yyrw_glxx_sb";
      this.table_yyrw_glxx_sb = Object.assign({}, obj);
      // this.table_yyrw_glxx_sb.pageSize = 50;
      // this.table_yyrw_glxx_sb.pageList = [50];
      // this.table_yyrw_glxx_sb.hiddenPageinfoLink = true;
      // this.table_yyrw_glxx_sb.paginationLoop = true;
      // this.table_yyrw_glxx_sb.paginationPreText = "<i class='fa fa-arrow-left'></i>上一页";
      // this.table_yyrw_glxx_sb.paginationNextText = "下一页<i class='fa fa-arrow-right'></i>";
      // this.table_yyrw_glxx_sb.height = this.commservice.getViewPort().height - this.commservice.topH - this.commservice.topmenuH - 240 - 110;
      this.table_yyrw_glxx_sb.height = this.commservice.getViewPort().height - this.commservice.topH - this.commservice.topmenuH - 240 - 110;
    }
  }

  @HostListener("window:myevents", ["$event"])
  myevents = {
    "click .view_dzwl": function (e, value, row, index) {
      // 查看电子围栏
      this.viewDtwl(value, row);
    }.bind(this),
    "click .eidte_dzwl": function (e, value, row, index) {
      // 修改/设置 电子围栏
      this.caozuo_ysrwwybsm = row.ysrwwybsm;
      this.editeDtwl(value, row);
    }.bind(this),
    "click .eidte_rwxx": function (e, value, row, index) {
      // 修改任务信息
      this.caozuo_ysrwwybsm = value;
      this.edite_rwbasexx(row);
    }.bind(this),
    "click .jcgl_car": function (e, value, row, index) {
      // 解除关联的车辆
      this.caozuo_ysrwbh = value;
      this.commservice.myswal("warning", "确定解除关联？", "", "cz", () => {
        this.jcglCar();
      });
    }.bind(this),
    "click .gl_car": function (e, value, row, index) {
      // 任务 关联车辆。 一对一
      this.caozuo_ysrwbh = value;
      this.s_obj_gltablecar.cph = ""; // 搜索条件还原为最初
      this.gltable_car = Object.assign({}, this.gltable_car);
      // 清空上次的选择
      this.glbh_car.length = 0;
      $("#glcar_Modal").modal({
        keyboard: true,
        backdrop: "static"
      });
    }.bind(this),
    "click .jcgl_ry": function (e, value, row, index) {
      //解除关联的人员
      this.caozuo_ysrwbh = value;
      this.commservice.myswal("warning", "确定解除关联？", "", "cz", () => {
        this.jcglRy();
      });
    }.bind(this),
    "click .gl_ry": function (e, value, row, index) {
      // 任务关联人员    一对多
      this.caozuo_ysrwbh = value;
      $("#rylxSelect").selectpicker("val", ""); // 请选择
      this.s_obj_gltablery.rylxm = "";
      this.s_obj_gltablery.xm = "";
      this.s_obj_gltablery.sfzjhm = "";
      this.gltable_ry = Object.assign({}, this.gltable_ry);
      // 清空上次选择的数据
      this.selectryCache.length = 0;
      $("#glry_Modal").modal({
        keyboard: true,
        backdrop: 'static'
      })

    }.bind(this),
    "click .jcgl_sb": function (e, value, row, index) {
      //解除关联的设备
      this.caozuo_ysrwbh = value;
      this.commservice.myswal("warning", "确定解除关联？", "", "cz", () => {
        this.jcglSb();
      });
    }.bind(this),
    "click .gl_sb": function (e, value, row, index) {
      //任务关联设备  （终端设备 一对一    电子标签设备 一对多）
      this.caozuo_ysrwbh = value;
      this.activeTab_gl = "glzdsb";
      this.s_obj_gltablezdsb.id = "";
      this.gltable_zdsb = Object.assign({}, this.gltable_zdsb);
      $('.tabbable-custom a[href="#gl_zdsb"]').tab("show");
      // 清空上次选择的数据
      this.glbh_zdsb.length = 0;
      $("#glsb_Modal").modal({
        keyboard: true,
        backdrop: 'static'
      })
    }.bind(this),
    "click .infosjbxx": function (e, value, row, index) {
      // 选择关联的电子标签表格中， 试卷包的详细信息
      this.xqobj_sjbxx = {
        from: "zdsb_glbqsb_sjbxx",
        keyValue: {
          sjbsjxxList: value ? value : []
        }
      };
      $("#xq_kglbqsjbModal").modal({
        keyboard: true,
        backdrop: "static"
      });
    }.bind(this),
    "click .ckglxx_yyrw": function (e, value, row, index) {
      const ysrwbhv = row.ysrwbh;
      if (!ysrwbhv) {
        return
      }
      this.viewglxx(ysrwbhv);
    }.bind(this)
  }

  /**
   * 查看电子标签的关联信息（试卷包的信息）
   * @param {string} bh
   */
  viewglxx(bh: string): void {
    const url = "sjgz/jcsjgl/cxglsjbxx";
    this.itservice.kwPtPost(url, {
      ksjhbh: this.s_obj_glxx.ksjhbh,
      cxlx: "sjysrw",
      bh: bh
    }).subscribe(resp => {
      this.commservice.handResponse("get", url, resp, (arg1, resp, arg2) => {
        if (arg1) {
          if (arg2) {
            const glsjbxxListv = resp.glsjbxxList ? resp.glsjbxxList : [];
            this.glsjbxxList = glsjbxxListv;
            $("#viewglxx_Modal").modal({
              keyboard: true,
              backdrop: "static"
            });
          }
        } else {
          this.viewglxx(bh);
        }
      });
    });
  }

  /**
   * 查看地图围栏和 出发地目的地
   * @param {string} value
   */
  viewDtwl(value: string, row: any): void {
    this.dtwlactionflag = "view";
    // 保持鼠标绘制地图空白
    this.map.remove(this.polygonList);
    this.viewpolygon.hide();
    const dtwlstr = value;
    if (dtwlstr) {
      try {
        const wlarr = JSON.parse(dtwlstr);
        this.viewpolygon.show();
        this.viewpolygon.setPath(wlarr);
      } catch (e) {

      }
    }
    // 设置出发地和目的地 marker显示
    const cfdPostion = [row.cfdjd, row.cfdwd];
    const mddPostion = [row.mddjd, row.mddwd];
    this.cfdMarker.hide();
    this.mddMarker.hide();
    if (cfdPostion.length && mddPostion.length) {
      this.setPositionDZ(row.cfdmc, cfdPostion, row.mddmc, mddPostion);
    }
    $("#dtwl_Modal").modal({
      keyboard: true,
      backdrop: "static"
    });
  }

  /**
   * 设置/编辑地图围栏
   * @param {string} value
   * @param row
   */
  editeDtwl(value: string, row: any): void {
    // 保持鼠标绘制地图空白
    this.map.remove(this.polygonList);
    this.viewpolygon.hide();
    const dtwlstr = value;
    if (dtwlstr) {
      // 存在地图围栏数据，修改操作
      //1: 初始化显示
      this.dtwlactionflag = "edite";
      try {
        const wlarr = JSON.parse(dtwlstr);
        this.viewpolygon.show();
        this.viewpolygon.setPath(wlarr);
      } catch (e) {

      }
    } else {
      // 不存在地图围栏数据,设置操作
      this.dtwlactionflag = "add";
    }
    // 设置出发地和目的地 marker显示
    const cfdPostion = [row.cfdjd, row.cfdwd];
    const mddPostion = [row.mddjd, row.mddwd];
    this.cfdMarker.hide();
    this.mddMarker.hide();
    if (cfdPostion.length && mddPostion.length) {
      this.setPositionDZ(row.cfdmc, cfdPostion, row.mddmc, mddPostion);
    }
    $("#dtwl_Modal").modal({
      keyboard: true,
      backdrop: "static"
    });
  }

  /**
   * 清空地图围栏
   */
  clearDtwl(): void {
    //this.map.remove(this.viewpolygon); // 不能把this.viewpolygon这个对象清掉
    this.viewpolygon.setPath([]);
  }

  /**
   * 设置该任务的出发地 和  目的地  的marker位置
   * @param cfdposition
   * @param mddposition
   */
  setPositionDZ(cfdmc: string, cfdposition: any, mddmc: string, mddposition: any): void {
    this.cfdMarker.show();
    this.mddMarker.show();
    this.cfdMarker.setPosition(cfdposition);
    this.cfdMarker.setLabel({
      content: "<span style='border:none;color:red;'>" + cfdmc + "</span>",
      offset: new AMap.Pixel(-5, 18), //修改label相对于maker的位置(相对marker的左上角)
    });
    this.mddMarker.setPosition(mddposition);
    this.mddMarker.setLabel({
      content: "<span style='border:none;color:red;'>" + mddmc + "</span>",
      offset: new AMap.Pixel(-5, 18), //修改label相对于maker的位置(相对marker的左上角)
    });
  }

  /**
   * 编辑任务信息
   */
  edite_rwbasexx(row: any): void {
    const zfzrxmv = this.commservice.removeSpace(false, row.zfzrxm); // 总负责人姓名
    const sfzjlxmv = this.commservice.removeSpace(false, row.sfzjlxm); //身份证件类型码
    const sfzjhmv = this.commservice.removeSpace(false, row.sfzjhm); // 身份证件号码
    this.formgroup_rwbasexx.patchValue({
      zfzrxmCtr: zfzrxmv,
      sfzjlxmCtr: sfzjlxmv ? sfzjlxmv : this.selectDefaultField.sfzjlxm,
      sfzjhmCtr: sfzjhmv
    });
    $("#sfzjlxselect").selectpicker("render");
    $("#add_rwbasexxModal").modal({
      keyboard: true,
      backdrop: "static"
    });
  }

  /**
   * 运送任务基础信息，修改表单
   */
  createformgroup_rwbasexx(): void {
    this.formgroup_rwbasexx = this.fb.group({
      zfzrxmCtr: [""],
      sfzjlxmCtr: [""]
    });
    const sfzjlxmCtrv = this.formgroup_rwbasexx.get('sfzjlxmCtr') as FormControl;
    const add_sfzjhmCtr = new FormControl("", [this.myValidator.numMatchlx(sfzjlxmCtrv)]) as FormControl;
    this.formgroup_rwbasexx.addControl("sfzjhmCtr", add_sfzjhmCtr);
    this.getzd(); // 字典数据，  身份证件类型，民族，外语语种
  }

  /**
   * 获取码表字典数据
   * 身份证件类型
   * 民族
   * 外语语种
   */
  getzd(): void {
    const search_mbs = "gj_sfzjdmb";
    this.commservice.getmbzd(search_mbs, (resp, flag2) => {
      if (flag2) {
        const zdArr = resp;
        const sfzjlxList = zdArr[0]; // 身份证件类型
        // 身份证件类型
        $("#sfzjlxselect").empty();
        let str_sfrzjlx: string = "";
        sfzjlxList.forEach((item) => {
          str_sfrzjlx += "<option value='" + item.DM + "'>" + item.MC + "</option>";
        });
        $("#sfzjlxselect").append(str_sfrzjlx);
        $("#sfzjlxselect").selectpicker({
          size: 5
        });
        this.selectDefaultField.sfzjlxm = sfzjlxList[0].DM;
      } else {
        this.commservice.myswal("warning", resp, "", "ts", null);
      }
    });
  }

  /**
   * 验证+ 保存   任务的基本信息
   */
  sure_editeRwxx(): void {
    if (this.formgroup_rwbasexx.invalid) {
      const ctrols = this.formgroup_rwbasexx.controls;
      for (let path in ctrols) {
        ctrols[path].markAsDirty();
        ctrols[path].updateValueAndValidity();
      }
      return
    }
    const formgroupv = this.formgroup_rwbasexx.getRawValue();
    const zfzrxmv = this.commservice.removeSpace(false, formgroupv.zfzrxmCtr);
    const sfzjlxmv = this.commservice.removeSpace(false, formgroupv.sfzjlxmCtr);
    const sfzjlxv = this.commservice.removeSpace(false, $("#sfzjlxselect option:selected").text());
    const sfzjhmv = this.commservice.removeSpace(false, formgroupv.sfzjhmCtr);
    this.commservice.blockUI({
      boxed: true,
      message: "保存中...",
      zIndex: 10051,
      overlayColor: "#67809F"
    });
    const url = "sjgz/rwjh/xgysrwxx";
    this.itservice.kwPtPost(url, {
      ysrwwybsm: this.caozuo_ysrwwybsm,
      zfzrxm: zfzrxmv,
      sfzjlxm: sfzjlxmv,
      sfzjlx: sfzjlxv,
      sfzjhm: sfzjhmv
    }).subscribe(resp => {
      this.commservice.handResponse("put", url, resp, (arg1, resp, arg2) => {
        if (arg1) {
          if (arg2) {
            this.commservice.myswal("success", resp, "", "ts", null);
            this.table_yyrw_rwxx = Object.assign({}, this.table_yyrw_rwxx);
            $("#add_rwbasexxModal").modal("hide");
          } else {
            this.commservice.myswal("warning", resp, "", "ts", null);
          }
        } else {
          this.sure_editeRwxx();
        }
      });
    })
  }

  /**
   * 解除任务和 车辆的关联
   */
  jcglCar(): void {
    const url = "sjgz/jcsjgl/jcYsrwclgl";
    this.itservice.kwPtPost(url, {
      ysrwbh: this.caozuo_ysrwbh,
      ksjhbh: this.s_obj_glxx.ksjhbh
    }).subscribe(resp => {
      this.commservice.handResponse("put", url, resp, (arg1, resp, arg2) => {
        if (arg1) {
          if (arg2) {
            this.commservice.myswal("success", resp, "", "ts", null);
            this.table_yyrw_glxx_car = Object.assign({}, this.table_yyrw_glxx_car);
          } else {
            this.commservice.myswal("warning", resp, "", "ts", null);
          }
        } else {
          this.jcglCar();
        }
      });
    });
  }

  /**
   * 解除任务和 人员的关联
   */
  jcglRy(): void {
    const url = "sjgz/jcsjgl/jcYsrwrygl";
    this.itservice.kwPtPost(url, {
      ysrwbh: this.caozuo_ysrwbh,
      ksjhbh: this.s_obj_glxx.ksjhbh
    }).subscribe(resp => {
      this.commservice.handResponse("put", url, resp, (arg1, resp, arg2) => {
        if (arg1) {
          if (arg2) {
            this.commservice.myswal("success", resp, "", "ts", null);
            this.table_yyrw_glxx_ry = Object.assign({}, this.table_yyrw_glxx_ry);
          } else {
            this.commservice.myswal("warning", resp, "", "ts", null);
          }
        } else {
          this.jcglRy();
        }
      });
    });
  }

  /**
   * 解除任务和 设备的关联
   */
  jcglSb(): void {
    const url = "sjgz/jcsjgl/jcYsrwsbgl";
    this.itservice.kwPtPost(url, {
      ysrwbh: this.caozuo_ysrwbh,
      ksjhbh: this.s_obj_glxx.ksjhbh
    }).subscribe(resp => {
      this.commservice.handResponse("put", url, resp, (arg1, resp, arg2) => {
        if (arg1) {
          if (arg2) {
            this.commservice.myswal("success", resp, "", "ts", null);
            this.table_yyrw_glxx_sb = Object.assign({}, this.table_yyrw_glxx_sb);
          } else {
            this.commservice.myswal("warning", resp, "", "ts", null);
          }
        } else {
          this.jcglSb();
        }
      });
    });
  }

  /**
   * 关联车 / 人员 / 设备的表格查询表单
   */
  createsearchform_glxxN(): void {
    //N 代表三个关联关系使用同一个数据源
    const N_sfgldata = [{
      code: "1",
      name: "未关联"
    }, {
      code: "0",
      name: "已关联"
    }];
    $("#glcar_select").empty();
    $("#glry_select").empty();
    $("#glsb_select").empty();
    let str_N: string = "";
    N_sfgldata.forEach((item) => {
      str_N += "<option value='" + item.code + "'>" + item.name + "</option>";
    });
    $("#glcar_select").append(str_N);
    $("#glry_select").append(str_N);
    $("#glsb_select").append(str_N);
    $("#glcar_select").selectpicker({
      size: 5
    });
    $("#glry_select").selectpicker({
      size: 5
    });
    $("#glsb_select").selectpicker({
      size: 5
    });
    this.selectDefaultField.sfglcl = N_sfgldata[0].code;
    this.selectDefaultField.sfglry = N_sfgldata[0].code;
    this.selectDefaultField.sfglsb = N_sfgldata[0].code;
  }

  /**
   * 获取押送计划列表
   */
  getysjhSelect(): void {
    const url = "sjgz/rwjh/cxsjysjhlb";
    this.itservice.kwPtPost(url, {
      ysjhmc: "",
      ksjhbh: this.s_obj.ksjhbh,
      pageNum: 1,
      pageSize: 9999
    }).subscribe(resp => {
      this.commservice.handResponse("get", url, resp, (arg1, resp, arg2) => {
        if (arg1) {
          if (arg2) {
            const sjysjhList = resp.sjysjhList ? resp.sjysjhList : [];
            this.createselect(sjysjhList);
          }
        }
      });
    });
  }

  createselect(data: any[]): void {
    $("#ysjhselect_rwxx").empty();
    $("#ysjhselect_glcar").empty();
    $("#ysjhselect_glry").empty();
    $("#ysjhselect_glsb").empty();
    let str: string = "<option value=''>--请选择--</option>";
    data.forEach((item) => {
      str += "<option value='" + item.ysjhbh + "'>" + item.ysjhmc + "</option>";
    });
    $("#ysjhselect_rwxx").append(str);
    $("#ysjhselect_glcar").append(str);
    $("#ysjhselect_glry").append(str);
    $("#ysjhselect_glsb").append(str);
    $("#ysjhselect_rwxx").selectpicker({
      size: 5
    });
    $("#ysjhselect_glcar").selectpicker({
      size: 5
    });
    $("#ysjhselect_glry").selectpicker({
      size: 5
    });
    $("#ysjhselect_glsb").selectpicker({
      size: 5
    });
  }


  initmap(): void {
    const that = this;
    this.map = new AMap.Map("mapRoom", {
      resizeEnable: true,
      zoom: 8,
    });
    this.viewpolygon = new AMap.Polygon({
      map: this.map,
      fillColor: '#80d8ff',
      strokeColor: '#00b0ff',
      strokeWeight: 3
    });
    this.viewpolygon.hide();
    this.cfdMarker = new AMap.Marker({
      map: this.map,
      offset: new AMap.Pixel(-9, -9),
      visible: false, // 默认不可见，当年点击了 查看的时候显示
    });
    this.mddMarker = new AMap.Marker({
      map: this.map,
      offset: new AMap.Pixel(-9, -9),
      visible: false, // 默认不可见，当年点击了 查看的时候显示
    });
    this.map.plugin(["AMap.MouseTool"], function () {
      //在地图中添加MouseTool插件
      const mouseTool = new AMap.MouseTool(that.map);
      //用鼠标工具画多边形
      const drawPolygon = mouseTool.polygon({
        fillColor: '#80d8ff',
        strokeColor: '#00b0ff',
        strokeWeight: 3
      });

      //添加绘制完成的事件
      AMap.event.addListener(mouseTool, 'draw', function (e) {
        const fgwobj = e.obj; // 覆盖物对象，这里是 多边形对象
        // 每当一个多边形绘制完成，就需要把前面绘制的删除
        that.map.remove(that.polygonList);
        that.polygonList.length = 0;
        // 然后把当前的多边形对象保存起来
        that.polygonList.push(fgwobj);
      });
    });
  }

  /**
   * 地图围栏的 保存操作（add/edite）
   */
  dtwlDone(): void {
    if (!this.polygonList.length) {
      this.commservice.myswal("warning", "请绘制地图围栏", "", "ts", null);
      return
    }
    const savepolygon = this.polygonList[0]; // 第一个对边行对象
    const polygonPath = savepolygon.getPath();
    const savedatalist: any[] = [];
    polygonPath.forEach((item) => {
      savedatalist.push([item.lng, item.lat]);
    });
    this.commservice.blockUI({
      boxed: true,
      message: "保存中...",
      zIndex: 10051,
      overlayColor: "#67809F"
    });
    const url = "sjgz/rwjh/xgysrwxx";
    this.itservice.kwPtPost(url, {
      ysrwwybsm: this.caozuo_ysrwwybsm,
      dtwl: JSON.stringify(savedatalist)
    }).subscribe(resp => {
      this.commservice.handResponse("put", url, resp, (arg1, resp, arg2) => {
        if (arg1) {
          if (arg2) {
            this.commservice.myswal("success", resp, "", "ts", null);
            $("#dtwl_Modal").modal("hide");
            this.table_yyrw_rwxx = Object.assign({}, this.table_yyrw_rwxx);
          } else {
            this.commservice.myswal("warning", resp, "", "ts", null);
          }
        } else {
          this.dtwlDone();
        }
      })
    })
  }

  /**
   * 关联任务的 车辆表格
   */
  inittable_glcar(): void {
    const that = this;
    this.gltable_car = {
      tableid: "gltable_car",
      url: "sjgz/jcsj/sjcllb",
      height: 500,
      reqobj: this.s_obj_gltablecar,
      sidePagination: "server",
      pageSize: 10,
      pageList: [10, 20, 30],
      total: "totalRows",
      rows: "sjclList",
      columns: [{
        radio: true
      }, {
        title: "车牌号",
        field: "cph",
        cellStyle: function () {
          return {
            classes: 'td1'
          }
        }
      }, {
        title: "车型",
        field: "cx",
        cellStyle: function () {
          return {
            classes: 'td2'
          }
        }
      }, {
        title: "车辆品牌",
        field: "clpp",
        cellStyle: function () {
          return {
            classes: 'td3'
          }
        }
      }, {
        title: "车辆来源",
        field: "clly",
        cellStyle: function () {
          return {
            classes: 'td4'
          }
        }
      }, {
        title: "创建机构名称",
        field: "cjjgmc",
        cellStyle: function () {
          return {
            classes: 'td1'
          }
        }
      }]
    };
    // this.gltable_car.pageSize = 50;
    // this.gltable_car.pageList = [50];
    // this.gltable_car.hiddenPageinfoLink = true;
    // this.gltable_car.paginationLoop = true;
    // this.gltable_car.paginationPreText = "<i class='fa fa-arrow-left'></i>上一页";
    // this.gltable_car.paginationNextText = "下一页<i class='fa fa-arrow-right'></i>";
    //this.gltable_car.height = this.commservice.getViewPort().height - this.commservice.topH - this.commservice.topmenuH - 240 - 50;
    this.gltable_car.height = this.commservice.getViewPort().height - this.commservice.topH - this.commservice.topmenuH - 240 - 50;
  }

  /**
   * 关联任务的 人员表格
   */
  inittable_glry(): void {
    const that = this;
    this.gltable_ry = {
      tableid: "gltable_ry",
      url: "sjgz/jcsj/yyrylb",
      height: 500,
      reqobj: this.s_obj_gltablery,
      sidePagination: "server",
      pageSize: 10,
      pageList: [10, 20, 30],
      total: "totalRows",
      rows: "yyryList",
      columns: [{
        checkbox: true
      }, {
        title: "姓名",
        field: "xm",
        cellStyle: function () {
          return {
            classes: 'td1'
          }
        }
      }, {
        title: "性别",
        field: "xb",
        cellStyle: function () {
          return {
            classes: 'td2'
          }
        }
      }, {
        title: "身份证件类型",
        field: "sfzjlx",
        cellStyle: function () {
          return {
            classes: 'td3'
          }
        }
      }, {
        title: "身份证件号码",
        field: "sfzjhm",
        cellStyle: function () {
          return {
            classes: 'td4'
          }
        }
      }, {
        title: "人员类型",
        field: "rylx",
        cellStyle: function () {
          return {
            classes: 'td1'
          }
        }
      }, {
        title: "联系电话",
        field: "lxdh",
        cellStyle: function () {
          return {
            classes: 'td2'
          }
        }
      }, {
        title: "创建机构名称",
        field: "cjjgmc",
        cellStyle: function () {
          return {
            classes: 'td3'
          }
        }
      }]
    };
    // this.gltable_ry.pageSize = 50;
    // this.gltable_ry.pageList = [50];
    // this.gltable_ry.hiddenPageinfoLink = true;
    // this.gltable_ry.paginationLoop = true;
    // this.gltable_ry.paginationPreText = "<i class='fa fa-arrow-left'></i>上一页";
    // this.gltable_ry.paginationNextText = "下一页<i class='fa fa-arrow-right'></i>";
    // this.gltable_ry.height = this.commservice.getViewPort().height - this.commservice.topH - this.commservice.topmenuH - 240 - 50;
    this.gltable_ry.height = this.commservice.getViewPort().height - this.commservice.topH - this.commservice.topmenuH - 240 - 50;
  }


  /**
   *
   * 关联任务的   设备页面tab切换
   * @param {string} tabv
   * glzdsb
   * gldzbqsb
   */
  tabTogglegl(tabv: string): void {
    this.activeTab_gl = tabv;
    if (tabv == "glzdsb") {
      this.s_obj_gltablezdsb.id = "";
      this.gltable_zdsb = Object.assign({}, this.gltable_zdsb);
      this.glbh_zdsb.length = 0;
    } else if (tabv == "gldzbqsb") {
      //this.s_obj_gltablebqsb.id = "";
      this.inittable_glsb_dzbqsb();
      this.selectbqsbCache.length = 0;
    }
  }

  /**
   * 关联任务的   手持终端设备表格
   */
  inittable_glsb_zdsb(): void {
    const that = this;
    this.gltable_zdsb = {
      tableid: "gltable_zdsb",
      url: "sjgz/jcsj/sczdsblb",
      reqobj: this.s_obj_gltablezdsb,
      sidePagination: "server",
      height: 450,
      pageSize: 10,
      pageList: [10, 20, 30],
      total: "totalRows",
      rows: "sczdsbList",
      columns: [{
        radio: true
      }, {
        title: "终端名称",
        field: "sczdmc",
        cellStyle: function () {
          return {
            classes: 'td1'
          }
        }
      }, {
        title: "终端ID",
        field: "id",
        cellStyle: function () {
          return {
            classes: 'td2'
          }
        }
      }, {
        title: "型号",
        field: "xh",
        cellStyle: function () {
          return {
            classes: 'td3'
          }
        }
      }, {
        title: "手机号",
        field: "sjhm",
        cellStyle: function () {
          return {
            classes: 'td4'
          }
        }
      }, {
        title: "序列号",
        field: "xlh",
        cellStyle: function () {
          return {
            classes: 'td1'
          }
        }
      }, {
        title: "故障状态",
        field: "gzzt",
        cellStyle: function () {
          return {
            classes: 'td2'
          }
        },
        formatter: function (v) {
          let retstr: string = "";
          if (v == "0") {
            retstr = "正常";
          } else if (v == "1") {
            retstr = "异常";
          }
          return retstr;
        }
      }, {
        title: "最近心跳时间",
        field: "zjxtsj",
        cellStyle: function () {
          return {
            classes: 'td3'
          }
        }
      }]
    };
    // this.gltable_zdsb.pageSize = 50;
    // this.gltable_zdsb.pageList = [50];
    // this.gltable_zdsb.hiddenPageinfoLink = true;
    // this.gltable_zdsb.paginationLoop = true;
    // this.gltable_zdsb.paginationPreText = "<i class='fa fa-arrow-left'></i>上一页";
    // this.gltable_zdsb.paginationNextText = "下一页<i class='fa fa-arrow-right'></i>";
    //this.gltable_zdsb.height = this.commservice.getViewPort().height - this.commservice.topH - this.commservice.topmenuH - 240 - 110;
    //this.gltable_zdsb.height = this.commservice.getViewPort().height - this.commservice.topH - this.commservice.topmenuH - 240 - 110;

  }

  /**
   * 关联任务的    电子标签设备表格
   */
  inittable_glsb_dzbqsb(): void {
    this.gltable_bqsb = {
      tableid: "gltable_bqsb",
      url: "sjgz/jcsjsczdgl/gldzbqsjxxlb",
      reqobj: this.s_obj_gltablebqsb,
      sidePagination: "server",
      pageSize: 10,
      pageList: [10, 20, 30],
      total: "totalRows",
      rows: "ygldzbqsbList",
      height: 450,
      columns: [{
        checkbox: true
      }, {
        title: "标签ID",
        field: "id",
        cellStyle: function () {
          return {
            classes: 'td1'
          }
        }
      }, {
        title: "型号",
        field: "xh",
        cellStyle: function () {
          return {
            classes: 'td2'
          }
        }
      }, {
        title: "试卷包名称",
        field: "sjbsjxxList",
        cellStyle: function () {
          return {
            classes: 'td3'
          }
        },
        events: this.myevents,
        formatter: function (v, row) {
          let retstr: string = "";
          // let kmlist: any[] = [];
          // if (v && v.length) {
          //   kmlist = v.map((item) => {
          //     return item.kmmc
          //   });
          // }
          // if (kmlist.length) {
          //   let kmstr: string = kmlist.join(";");
          //   kmstr = that.commservice.showTenchart(kmstr, 10);
          //   retstr += "<span>" + kmstr + "</span>";
          // }
          if (v && v.length) {
            retstr += "<span>" + row.glsjbmc + "</span>";
            retstr += "&nbsp;&nbsp;<button  type='button' class='btn btn-xs btn-primary infosjbxx'><i class='fa fa-search'></i>试卷包详情</button>"
          } else {
            retstr += "<span>未关联试卷包</span>";
          }
          return retstr;
        }
      }]
    };
    // this.gltable_bqsb.pageSize = 50;
    // this.gltable_bqsb.pageList = [50];
    // this.gltable_bqsb.hiddenPageinfoLink = true;
    // this.gltable_bqsb.paginationLoop = true;
    // this.gltable_bqsb.paginationPreText = "<i class='fa fa-arrow-left'></i>上一页";
    // this.gltable_bqsb.paginationNextText = "下一页<i class='fa fa-arrow-right'></i>";
    //this.gltable_bqsb.height = this.commservice.getViewPort().height - this.commservice.topH - this.commservice.topmenuH - 240 - 110;
    //this.gltable_bqsb.height = this.commservice.getViewPort().height - this.commservice.topH - this.commservice.topmenuH - 240 - 110;
  }


  tableHander(e: any): void {
    const tableid = e.tableid;
    const caozuo = e.caozuo;
    const row = e.row;
    switch (tableid) {
      case "gltable_car": {
        if (caozuo == "onCheck") {
          this.glbh_car = [row.sjclbh];
        }
      }
        break;
      case "gltable_ry": {
        if (caozuo === "onCheck") {
          this.selectryCache = this.selectryCache.concat(row);
          this.selectryCache = this.commservice.fliterobjRepeat(this.selectryCache, "yyrybh");
        } else if (caozuo === "onUncheck") {
          const del_rybh = row.yyrybh;
          for (let i = 0; i < this.selectryCache.length; i++) {
            if (this.selectryCache[i].yyrybh == del_rybh) {
              this.selectryCache.splice(i, 1);
              break;
            }
          }
        } else if (caozuo === "onCheckAll") {
          this.selectryCache = this.selectryCache.concat(row);
          this.selectryCache = this.commservice.fliterobjRepeat(this.selectryCache, "yyrybh");
        } else if (caozuo === "onUncheckAll") {
          const selectrow = $("#gltable_ry").bootstrapTable("getData");
          const uncheckbhlist = selectrow.map((item) => {
            return item.yyrybh;
          });
          this.selectryCache = this.selectryCache.filter((item) => {
            const rybhv = item.yyrybh;
            return uncheckbhlist.indexOf(rybhv) == -1;
          });
        } else if (caozuo == "onPostBody") {
          // 根据右侧已经选择的数据，在切换页面的时候，吧当前页面的数据，给够选上
          const cachebhlist = this.selectryCache.map((item) => {
            return item.yyrybh;
          });
          $("#gltable_ry").bootstrapTable("checkBy", { field: "yyrybh", values: cachebhlist });
        }
      }
        break;
      case "gltable_zdsb": {
        if (caozuo == "onCheck") {
          this.glbh_zdsb = [row.sczdbh];
        }
      }
        break;
      case "gltable_bqsb": {
        if (caozuo === "onCheck") {
          this.selectbqsbCache = this.selectbqsbCache.concat(row);
          this.selectbqsbCache = this.commservice.fliterobjRepeat(this.selectbqsbCache, "dzbqbh");
        } else if (caozuo === "onUncheck") {
          const del_bqbh = row.dzbqbh;
          for (let i = 0; i < this.selectbqsbCache.length; i++) {
            if (this.selectbqsbCache[i].dzbqbh == del_bqbh) {
              this.selectbqsbCache.splice(i, 1);
              break;
            }
          }
        } else if (caozuo === "onCheckAll") {
          this.selectbqsbCache = this.selectbqsbCache.concat(row);
          this.selectbqsbCache = this.commservice.fliterobjRepeat(this.selectbqsbCache, "dzbqbh");
        } else if (caozuo === "onUncheckAll") {
          const selectrow = $("#gltable_bqsb").bootstrapTable("getData");
          const uncheckbhlist = selectrow.map((item) => {
            return item.dzbqbh;
          });
          this.selectbqsbCache = this.selectbqsbCache.filter((item) => {
            const bqbhv = item.dzbqbh;
            return uncheckbhlist.indexOf(bqbhv) == -1;
          });
        } else if (caozuo == "onPostBody") {
          // 根据右侧已经选择的数据，在切换页面的时候，吧当前页面的数据，给够选上
          const cachebhlist = this.selectbqsbCache.map((item) => {
            return item.dzbqbh;
          });
          $("#gltable_bqsb").bootstrapTable("checkBy", { field: "dzbqbh", values: cachebhlist });
        }
      }
        break;
    }
  }

  /**
   * 清空选择的人
   */
  removeAll_selectdry(): void {
    this.selectryCache.length = 0;
    $("#gltable_ry").bootstrapTable("uncheckAll");
  }

  /**
   * 清空选择的电子标签设备
   */
  removeAll_selectdbqsb(): void {
    this.selectbqsbCache.length = 0;
    $("#gltable_bqsb").bootstrapTable("uncheckAll");
  }

  /**
   * 删除某一个选中的人
   * @param obj
   */
  removeryCache(obj: any, index: number): void {
    this.selectryCache.splice(index, 1);
    //左侧表格勾选去掉
    $("#gltable_ry").bootstrapTable("uncheckBy", { field: "yyrybh", values: [obj.yyrybh] });
  }

  /**
   * 删除某一个选中的 电子标签设备
   * @param obj
   * @param {number} index
   */
  removebqsbCache(obj: any, index: number): void {
    this.selectbqsbCache.splice(index, 1);
    //左侧表格勾选去掉
    $("#gltable_bqsb").bootstrapTable("uncheckBy", { field: "dzbqbh", values: [obj.dzbqbh] });
  }

  showRemovebtn(obj: any): void {
    obj.showremovecellbtn = true;
  }

  hideRemovebtn(obj: any): void {
    obj.showremovecellbtn = false;
  }

  /**
   * 判段+ 保存任务和  车辆/人员/设备 的关联
   * @param {string} gldx
   * car
   * ry
   * sb
   */
  glsureDone(gldx: string): void {
    switch (gldx) {
      case "car": {
        if (!this.glbh_car.length) {
          this.commservice.myswal("warning", "请选择一个关联的车辆", "", "ts", null);
          return
        }
        const url = "sjgz/jcsjgl/ysrwGlsjcl";
        this.itservice.kwPtPost(url, {
          ysrwbh: this.caozuo_ysrwbh,
          sjclbhs: this.glbh_car,
          ksjhbh: this.s_obj_glxx.ksjhbh
        }).subscribe(resp => {
          this.commservice.handResponse("put", url, resp, (arg1, resp, arg2) => {
            if (arg1) {
              if (arg2) {
                this.commservice.myswal("success", resp, "", "ts", null);
                this.table_yyrw_glxx_car = Object.assign({}, this.table_yyrw_glxx_car);
                $("#glcar_Modal").modal("hide");
              } else {
                this.commservice.myswal("warning", resp, "", "ts", null);
              }
            } else {
              this.glsureDone(gldx);
            }
          });
        });
      }
        break;
      case "ry": {
        if (!this.selectryCache.length) {
          this.commservice.myswal("warning", "未选择关联的人员", "", "ts", null);
          return
        }
        const yyrybhsv = this.selectryCache.map((item) => {
          return item.yyrybh;
        });
        const url = "sjgz/jcsjgl/ysrwGlYyry";
        this.itservice.kwPtPost(url, {
          ysrwbh: this.caozuo_ysrwbh,
          yyrybhs: yyrybhsv,
          ksjhbh: this.s_obj_glxx.ksjhbh
        }).subscribe(resp => {
          this.commservice.handResponse("put", url, resp, (arg1, resp, arg2) => {
            if (arg1) {
              if (arg2) {
                this.commservice.myswal("success", resp, "", "ts", null);
                this.table_yyrw_glxx_ry = Object.assign({}, this.table_yyrw_glxx_ry);
                $("#glry_Modal").modal("hide");
              } else {
                this.commservice.myswal("warning", resp, "", "ts", null);
              }
            } else {
              this.glsureDone(gldx);
            }
          });
        });
      }
        break;
      case "sb": {
        const reqobj: any = {
          ysrwbh: this.caozuo_ysrwbh,
          sbbhs: [],
          sblx: "",
          ksjhbh: this.s_obj_glxx.ksjhbh
        }
        if (this.activeTab_gl == "glzdsb") {
          reqobj.sbbhs = this.glbh_zdsb;
          reqobj.sblx = "sczdsb";
        } else if (this.activeTab_gl == "gldzbqsb") {
          reqobj.sbbhs = this.selectbqsbCache.map((item) => {
            return item.dzbqbh;
          });
          reqobj.sblx = "dzbqsb";
        }
        if (!reqobj.sbbhs.length) {
          this.commservice.myswal("warning", "未选择关联的设备", "", "ts", null);
          return
        }
        const url = "sjgz/jcsjgl/ysrwGlsb";
        this.itservice.kwPtPost(url, reqobj).subscribe(resp => {
          this.commservice.handResponse("put", url, resp, (arg1, resp, arg2) => {
            if (arg1) {
              if (arg2) {
                this.commservice.myswal("success", resp, "", "ts", null);
                this.table_yyrw_glxx_sb = Object.assign({}, this.table_yyrw_glxx_sb);
                $("#glsb_Modal").modal("hide");
              } else {
                this.commservice.myswal("warning", resp, "", "ts", null);
              }
            } else {
              this.glsureDone(gldx);
            }
          });
        })
      }
        break;
    }
  }


  /**
   * 可以关联的人员表格查询表单处理
   */
  createsearchfrom_glry(): void {
    // 人员类型
    const mbywmcstr = "jy_rylxdmb";
    this.commservice.getmbzd(mbywmcstr, (resp, flag) => {
      if (flag) {
        const rylxList = resp[0];
        $("#rylxSelect").empty();
        let str: string = "<option value=''>--请选择--</option>";
        rylxList.forEach((item) => {
          str += "<option value='" + item.DM + "'> " + item.MC + "</option>";
        });
        $("#rylxSelect").append(str);
        $("#rylxSelect").selectpicker({
          size: 5
        });
        this.s_obj_gltablery.rylxm = "";  // 全部查询
      }
    });
  }

  /**
   * 获取用户信息
   */
  getuserinfo(): void {
    this.commservice.getUserinfo((info) => {
      this.userinfo = info;
      this.initactions(); //用户按钮权限
    });
  }


  constructor(private commservice: CommService,
    private itservice: MyhttpService,
    private localStorageService: LocalStorageService,
    private fb: FormBuilder,
    private myValidator: MyValidator) {

  }

  ngOnInit() {
    this.getuserinfo();
    this.s_obj.ksjhbh = this.localStorageService.get("hksjh");
    this.s_obj_glxx.ksjhbh = this.localStorageService.get("hksjh");
    this.inittable_rwxx();
    this.createsearchform_glxxN();
    this.getysjhSelect();
    this.initmap();
    this.createformgroup_rwbasexx();
    // 关联
    this.s_obj_gltablezdsb.ksjhbh = this.localStorageService.get("hksjh");
    this.s_obj_gltablebqsb.ksjhbh = this.localStorageService.get("hksjh");
    this.inittable_glcar();
    this.createsearchfrom_glry();
    this.inittable_glry();
    this.inittable_glsb_zdsb();

    $('#dtwl_Modal').on('shown.bs.modal', () => {
      //设置地图自适应
      setTimeout(() => {
        this.map.setFitView([this.cfdMarker, this.mddMarker, this.viewpolygon]);
      }, 500)
    });
  }

  ngOnDestroy() {

  }

}
